package org.example.config;

import com.yubico.webauthn.RelyingParty;
import com.yubico.webauthn.data.RelyingPartyIdentity;
import org.example.service.PasskeyRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
public class WebAuthnConfig {

    @Resource
    private WebAuthnProperties webAuthnProperties;


    @Bean
    public RelyingParty relyingParty(PasskeyRepository credentialRepository) {
        return RelyingParty.builder()
            .identity(RelyingPartyIdentity.builder()
                .id(webAuthnProperties.getDomain())
                .name(webAuthnProperties.getName())
                .build())
            .credentialRepository(credentialRepository)
            .origins(webAuthnProperties.getOrigins())
            .build();
    }
}
